package com.harmontronics.hanma.paas.paas.domain.organization.repository.persistence;

import cn.hutool.core.collection.CollectionUtil;
import com.harmontronics.hanma.paas.paas.consts.NumberEnum;
import com.harmontronics.hanma.paas.paas.domain.organization.entity.valueobject.HmOrgFields;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.harmontronics.hanma.paas.paas.domain.organization.repository.mapper.HmOrgMapper;
import com.harmontronics.hanma.paas.paas.domain.organization.repository.po.HmOrgPO;
import org.springframework.stereotype.Repository;


@Repository("hmOrgRepository")
public class HmOrgRepository extends ServiceImpl<HmOrgMapper, HmOrgPO>{

    public IPage<HmOrgPO> selectPage(QueryWrapper<HmOrgPO> queryWrapper, Page<HmOrgPO> page) {
        return baseMapper.selectPage(page,queryWrapper);
    }

    public Map<Long, HmOrgPO> findAllOrg(){
        Map<Long, HmOrgPO> orgPOMap = new HashMap<>();
        List<HmOrgPO> allOrgs = list(
                new QueryWrapper<HmOrgPO>()
                        .eq(HmOrgFields.DELETED, NumberEnum.ZERO.getNum()));
        if(CollectionUtil.isNotEmpty(allOrgs)){
            allOrgs.forEach(item->{
                orgPOMap.put(item.getId(),item);
            });
        }
        return orgPOMap;
    }
}